<?php


namespace app\shop\controller\admin;


use app\shop\controller\BaseAdminController;
use app\shop\model\config\TypeBusinessModel;
use app\shop\model\config\TypeDesignModel;
use app\shop\model\config\TypeProgramModel;
use app\shop\model\order\OrderModel;
use app\shop\model\user\FriendModel;
use app\shop\model\user\UserModel;
use app\shop\service\user\FriendService;

class AllotOrderController extends BaseAdminController
{

    public function setModel()
    {
        return new OrderModel();
    }

    function setSearch()
    {
        $where = [];
        $where[] = ['order_status', '=', 0];
        return [
            'like' => ['order_sn', 'mobile'],
            'between_time' => ['create_time'],
            'custom' => $where,
        ];
    }

    function setSort()
    {
        // TODO: Implement setSort() method.
    }

    /**
     * 订单列表
     * @return array|\think\response\Json
     */
    public function getList()
    {
        try {
            $list = parent::getList();
            foreach ($list['data'] as &$v) {
                $v['design_type_name'] = TypeDesignModel::where('id', $v['design_type'])->value('name', '');
                $v['business_type_name'] = TypeBusinessModel::where('id', $v['business_type'])->value('name', '');
                $v['program_name'] = TypeProgramModel::where('id', $v['program_id'])->value('name', '');
                $v['order_status_txt'] = OrderModel::getOrderTxt($v['order_status']);
                $v['design_name'] = UserModel::where('user_id', $v['design_id'])->value('realname', '');
                $v['sale_name'] = UserModel::where('user_id', $v['sale_id'])->value('realname', '');
                $v['create_time'] = date('Y-m-d', strtotime($v['create_time']));
            }
            return $this->success($list);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 指派设计师和销售
     * @param array $data
     * @return bool|\think\response\Json
     */
    public function save(array $data = [])
    {
        try {
            $data = $this->request->param();

            $orderInfo = OrderModel::find($data['id']);

            $data['order_status'] = 1;
            parent::save($data);



            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }
}